/**
 * 用户管理  用户列表
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.deptName" placeholder="输入用户"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-select size="small" v-model="formInline.state" placeholder="请选择" @change="selectChange">
        <el-option v-for="item in payType" :label="item.key" :value="item.value" :key="item.value"></el-option>
        </el-select>
      </el-form-item> -->
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="nickname" label="昵称" width="150">
      </el-table-column>
      <el-table-column sortable prop="name" label="名字" width="150">
      </el-table-column>
      <el-table-column sortable prop="technician_address_city" label="地址" width="150">
      </el-table-column>
      <el-table-column sortable prop="phone" label="手机号" width="150">
      </el-table-column>
      <el-table-column sortable prop="balance" label="账户余额" width="150">
      </el-table-column>
      <el-table-column sortable prop="uuid" label="订单" width="150">
        <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="goOrder(scope.row.uuid)">查看订单</el-button>
        </template>
      </el-table-column>
      <el-table-column  label="操作" min-width="300">
        <template slot-scope="scope">
			    <el-button size="mini" type="danger" @click="handleEdit(scope.$index, scope.row,'封禁')" v-if="scope.row.state==0">封禁</el-button>
          <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row,'解封')" v-if="scope.row.state==1">解封</el-button>
          <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row,'同意注销')" v-if="scope.row.state==2">同意注销</el-button>
		      <el-button size="mini" type="primary" v-if="scope.row.state==2" @click="handleEdit(scope.$index, scope.row,'拒绝注销')">拒绝注销</el-button>
		      <el-button size="mini" type="info" v-if="scope.row.state==3" @click="handleEdit(scope.$index, scope.row,'取消注销')">取消注销</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
import { getUserList } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      formInline: {
        page: 1,
        pagenum: 10,
        city: '',
		    //state:null,
      },
      listData: [], //用户数据
      payType: [
        { key: '请选择', value: '' },
        { key: '正常代理', value: 0 },
        { key: '已封禁', value: 1 },
        { key: '申请注销', value: 2 },
        { key: '已注销', value: 3 },
      ],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    //选择器改变事件
    selectChange(e){
      if(this.formInline.state!==0&&!this.formInline.state){
        delete this.formInline.state;
      }
      this.getdata(this.formInline)
    },
    // 查看用户订单信息
    goOrder(uuid){
      this.$router.push({path:'/pay/OrderNew',query: {uuid:uuid}})
    },
    // 获取列表
    getdata(parameter) {
      this.loading = true
      getUserList(parameter).then(res => {
        this.loading = false
        this.$message({
          type: 'info',
          message: res.message
        })
        this.listData = res.date;
        // 分页赋值
        // this.pageparm.currentPage = this.formInline.page
        // this.pageparm.pageSize = this.formInline.limit
        this.pageparm.total = res.count
      }).catch(err => {
        this.loading = false
        this.$message.error('菜单加载失败，请稍后再试！')
      })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.pagenum = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    // 修改代理商状态
    handleEdit: function(index, row, type) {
      this.$confirm('确定要'+type+'吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let parameter={state:row.state,adminstratorID:row.ID};
        if(row.state==0){
          parameter.state=1;
        }else if(row.state==1){
          parameter.state=0;
        }else if(row.state==2){
          if(type=='同意注销'){
            parameter.state=3;
          }else if(type=='拒绝注销'){
            parameter.state=0;
          }
        }else if(row.state==3){
          parameter.state=0;
        }
        upStratorSta(parameter).then(res => {
          this.getdata(this.formInline)
        }).catch(err => {
          this.loading = false
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'+type
        })
      })
    },
  }
}
</script>

<style scoped lang="less">
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.avatar {
	width: 80px;
	height: 80px;
	display: block;
}
.avatar-uploader {
	.el-upload {
		border: 1px dashed #8c939d;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}
	.el-upload:hover {
		border-color: #409eff;
	}
}
.avatar-uploader-icon {
	border: 1px dashed #8c939d;
	font-size: 28px;
	color: #8c939d;
	width: 80px;
	height: 80px;
	line-height: 80px;
	text-align: center;
}
</style>

 